<?php
session_start();

include_once('libs/db.php');
include_once('config.php');

if (isset($_POST[ 'txt_unidad' ])) {
	
	$id = ($_POST[ 'id_elemento' ] != "") ? $_POST[ 'id_elemento' ] : 0;
	
	$query = "REPLACE elementos VALUES (
		{$id}, 
		'{$_POST[ 'txt_unidad' ]}',
		'{$_POST[ 'txt_codigo_b' ]}',
		'{$_POST[ 'txt_codigo_c' ]}',
		'{$_POST[ 'txt_codigo_d' ]}',
		'{$_POST[ 'txt_codigo_extra' ]}',
		'{$_POST[ 'txt_descripcion' ]}',
	    0, 
		NOW());";
		
	$result = mysql_query($query);
	if (!$result) {
		echo mysql_error($link);
		echo "<br />ERROR AL GRABAR LA UNIDAD DE MEDIDA.";
		exit;
	} else {
	    header('location:list_elementosAB.php');
	}
	exit;	
}

$btn_name = "Agregar";

?>
<html>
<head>
<script src='javascript\utils.js'></script>
<script src='javascript\new_elemento.js'></script>
<LINK href="common.css" rel="stylesheet" type="text/css">
</head>
<?php include_once('htx/header.php');?>

<form method=POST action='<?php $_SERVER[ 'PHP_SELF' ]?>' onsubmit='return false;'>
<div align=center style='top:100px' >
<fieldset id='fieldset'>
<legend>Alta elementos</legend><br/>
<table id='tbl_new' align=center >


<tr>
	<th>Unidad</th>
	<td><input type='text' name='txt_unidad' id='txt_unidad' value='' maxlength='6' size='10' /></td>
</tr>
<tr>
	<th>Codigo B</th>
	<td><input type='text' name='txt_codigo_b' id='txt_codigo_b' value='' maxlength='6' size='10' /></td>
</tr>
<tr>
	<th>Codigo C</th>
	<td><input type='text' name='txt_codigo_c' id='txt_codigo_c' value='' maxlength='6' size='10' /></td>
</tr>
<tr>
	<th>Codigo D</th>
	<td><input type='text' name='txt_codigo_d' id='txt_codigo_d' value='' maxlength='6' size='10' /></td>
</tr>
<tr>
	<th>Codigo Extra</th>
	<td><input type='text' name='txt_codigo_extra' id='txt_codigo_extra' value='' maxlength='6' size='10' /></td>
</tr>
<tr>
	<th>Descripcion</th>
	<td><input type='text' name='txt_descripcion' id='txt_descripcion' value='' maxlength='240' size='100' /></td>
</tr>

</table>
<table align=center >
<tr>
	<td><button name='btn_salir' class='button' onclick='javascript:volver()' ><img src='images/cancel.png' align=center /> Volver</button></td>
	<td><button name='btn_aceptar' class='button' onclick='javascript:check_data();' ><img src='images/add.png' align=center /> <?php print $btn_name;?></button></td>
</tr>
</table>
</fieldset>
</div>
<input type='hidden' name='id_elemento' value=''>
</form>
</body>